<template>
    <div>
        <table border="0">
            <tr>
                <th>标题</th>
                <th>类型</th>
                <th>国家</th>
                <th>缩略图</th>
                <th>操作</th>
            </tr>
            <tr v-for="item in newdata" :key="item.id">
                <td>{{item.title}}</td>
                <td @click="xiangqing(item.id)">{{item.content}}</td>
                <td>{{item.country}}</td>
                <td><img width="140px" :src="require('../assets'+item.imgUrl)" /></td>
                <td><span class="delBtn">删除</span></td>
            </tr>
        </table>
       <span @click="getpage(key)" class="span" v-for="key in num" :key="key">{{key}}</span>
    </div>
</template>
<script>

export default{
    data(){
        return{
            newdata:[],
            num:0
        }
    },
    created:async function(){
        let {data} =await this.$http.get("/api/getnew")
        // console.log(data);
        this.newdata = data
         let {data:dataAll} =await this.$http.get("/api/getcart")
         this.num = Math.ceil(dataAll.length /data.length)
    },
    methods:{
        xiangqing(id){
            this.$router.push({name:'detail',params:{id}});
        },
        getpage(p){
            let newp = this.$route.query.p
            if(p!=newp){
                this.$router.push({name:"newslist",query:{p}})
            }
            
        },
        
    },
    watch:{
          async $route(to){
               let p = to.query.p;
               let {data}=await this.$http.get("/api/getpage?p="+p)
            //    console.log(data);
                this.newdata=data
            }
        }
}
</script>
<style scoped>
 table {
    border-left: 1px solid #ebeef5;
    border-top: 1px solid #ebeef5;
    margin-top: 40px;
    width:100%;
    }
    table td,
    th {
    border-bottom: 1px solid #ebeef5;
    border-right: 1px solid #ebeef5;
    }
    .delBtn {
    cursor: pointer;
    }
    a{
      text-decoration:none;
    } 
    span{
        margin-right: 20px;
        display: inline-block;
        width: 50px;
        height: 25px;
        border: 1px solid skyblue;
        text-align: center;
        line-height: 25px;
        cursor: pointer;
    }
</style>
